Build Mamdani Systems (GUI)

문제: The Basic Tipping Problem

a two-input, one-output tipping problem

Given a number between 0 and 10 that represents the quality of service at a restaurant (where 10 is excellent), and another number between 0 and 10 that represents the quality of the food at that restaurant (again, 10 is excellent), what should the tip be?

규칙:

1.If the service is poor or the food is rancid, then tip is cheap.

2.If the service is good, then tip is average.

3. If the service is excellent or the food is delicious, then tip is generous.

사용 툴:

Fuzzy Inference System(FIS) Editor

handle high-level issues

the number of input and output variables

their names

Membership Function Editor

define the shapes of all membership functions

Rule Editor

edit the list of rules

Rule Viewer

view the fuzzy inference diagram

which rules are active

how individual membership function shapes influence the results

Surface Viewer

view the dependency of one of the outputs on any one or two of the inputs

generates and plot an output surface map

툴 사용 순서:

The FIS Editor: fuzzy (enter)

입력추가 및 이름설정

1.Select Edit > Add variable > Input.

A second yellow box labeled input2 appears.

2.Click the yellow box input1. This box is highlighted with a red outline.

3.Edit the Name field from input1 to service, and press Enter.

4.Click the yellow box input2. This box is highlighted with a red outline.

5.Edit the Name field from input2 to food, and press Enter.

6.Click the blue box output1.

7.Edit the Name field from output1 to tip, and press Enter.

8.Select File > Export > To Workspace.

멤버십함수 설정

Editor 활성화 방법

Within the FIS Editor window, select Edit > Membership Functions..

Within the FIS Editor window, double-click the blue icon called tip.

At the command line, type mfedit.

멤버함수 설정

Double-click the input variable service to open the Membership Function Editor.

In the Membership Function Editor, enter [0 10] in the Range and the Display Range fields.

Create membership functions for the input variable service.

Select Edit > Remove All MFs to remove the default membership functions for the input variable service.

Select Edit > Add MFs. to open the Membership Functions dialog box.

In the Membership Functions dialog box, select gaussmf as the MF Type.

Verify that 3 is selected as the Number of MFs.

Click OK to add three Gaussian curves to the input variable service.

Rename the membership functions for the input variable service, and specify their parameters.

Click on the curve named mf1 to select it, and specify the following fields in the Current Membership Function (click on MF to select) area:

In the Name field, enter poor.

In the Params field, enter [1.5 0].

The two inputs of Params represent the standard deviation and center for the Gaussian curve.

Click on the curve named mf2 to select it, and specify the following fields in the Current Membership Function (click on MF to select) area:

In the Name field, enter good.

In the Params field, enter [1.5 5].

Click on the curve named mf3, and specify the following fields in the Current Membership Function (click on MF to select) area:

In the Name field, enter excellent.

In the Params field, enter [1.5 10].

The Membership Function Editor window looks similar to the following figure.

In the FIS Variables area, click the input variable food to select it.

Enter [0 10] in the Range and the Display Range fields.

Create the membership functions for the input variable food.

Select Edit > Remove All MFs to remove the default Membership Functions for the input variable food.

Select Edit > Add MFs to open the Membership Functions dialog box.

In the Membership Functions dialog box, select trapmf as the MF Type.

Select 2 in the Number of MFs drop-down list.

Click OK to add two trapezoidal curves to the input variable food.

Rename the membership functions for the input variable food, and specify their parameters:

In the FIS Variables area, click the input variable food to select it.

Click on the curve named mf1, and specify the following fields in the Current Membership Function (click on MF to select) area:

In the Name field, enter rancid.

In the Params field, enter [0 0 1 3].

Click on the curve named mf2 to select it, and enter delicious in the Name field.

Reset the associated parameters if desired.

Click on the output variable tip to select it.

Enter [0 30] in the Range and the Display Range fields to cover the output range.

The inputs ranges from 0 to 10, but the output is a tip between 5% and 25%.

Rename the default triangular membership functions for the output variable tip, and specify their parameters.

Click the curve named mf1 to select it, and specify the following fields in the Current Membership Function (click on MF to select) area:

In the Name field, enter cheap.

In the Params field, enter [0 5 10].

Click the curve named mf2 to select it, and specify the following fields in the Current Membership Function (click on MF to select) area:

In the Name field, enter average.

In the Params field, enter [10 15 20].

Click the curve named mf3 to select it, and specify the following:

In the Name field, enter generous.

In the Params field, enter [20 25 30].

The Membership Function Editor looks similar to the following figure.

Now that the variables have been named and the membership functions have appropriate shapes and names, you can enter the rules. To call up the Rule Editor, go to the Edit menu and select Rules, or type ruleedit at the command line.

퍼지규칙 설정

Create rules by selecting an item in each input and output variable box, selecting one Connection item, and clicking Add Rule. You can choose none as one of the variable qualities to exclude that variable from a given rule and choose not under any variable name to negate the associated quality.

Delete a rule by selecting the rule and clicking Delete Rule.

Edit a rule by changing the selection in the variable box and clicking Change Rule.

Specify weight to a rule by typing in a desired number between 0 and 1 in Weight. If you do not specify the weight, it is assumed to be unity (1).

규칙추가

1. If (service is poor) or (food is rancid) then (tip is cheap) (1)

poor under the variable service

rancid under the variable food

The or radio button, in the Connection block

cheap, under the output variable, tip.

Then, click Add rule.

2.If (service is good) then (tip is average) (1)

3.If (service is excellent) or (food is delicious) then (tip is generous) (1)

동작확인

Rule Viewer 보기: View-Rules

입/출력 공간보기: View-Surface